/**
 * 
 */
package org.aitools.programd.processor.pluginManager;

import org.aitools.programd.Core;
import org.aitools.programd.parser.TemplateParser;
import org.aitools.programd.processor.ProcessorException;
import org.aitools.programd.processor.aiml.AIMLProcessor;
import org.w3c.dom.Element;

/**
 * @author Giuseppe Miceli
 *
 */
public class PluginDeactivation extends AIMLProcessor{

	public static String label = "plugindeactivation";

	public PluginDeactivation(Core coreToUse) {
		super(coreToUse);
		// TODO Auto-generated constructor stub
	}

	@Override
	public String process(Element element, TemplateParser parser)
			throws ProcessorException {
		
		if (element.getChildNodes() != null) {
			
			Boolean ret = false;
			try{
				String pluginName = parser.evaluate(element.getChildNodes()).trim(); 
				ret = core.deactivatePlugin(pluginName);
			}catch (Throwable t) {
				logger.fatal("Error during PluginDeactivation.process", t);
			}
			return String.valueOf(ret);
		} 
		else{
			throw new ProcessorException(
					"<plugindeactivation></plugindeactivation> must have content!", null);
		}
	}
}
